Repository navigation
fix(github): give each mock client its own HTTP transport - #413
Merged
Merged
Conversation
urlRewriteTransport delegated to the process-global http.DefaultTransport, so every mock client in the package shared one connection pool. That coupled all t.Parallel() tests to each other's httptest server teardown and produced intermittent "connection broken" failures that looked like regressions on unrelated PRs. Clone DefaultTransport per client so its settings are preserved while the pool is not shared, and drain idle connections on cleanup before the server closes. Verified with go test ./internal/github/ -race -count=20. Closes #401 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 98ae0c9c-bdbe-418e-8488-15082edca7dc
Contributor
Benchmarks:
|
Contributor
Benchmarks:
|
3 tasks done
jongio
added a commit
that referenced
this pull request
Aug 27, 2026
The gate ran every benchmark for the PR code, then every benchmark for the base code. Two contiguous blocks means two separate time windows, so anything that changed the runner between them (cold caches, CPU frequency ramp, a noisy neighbour) shifted one whole block at once. benchstat read that as a large, uniform, statistically significant regression across entire packages, including packages the PR could not reach. Tight variance and a small p-value did not rule this out. Same-runner comparison controls for runner-to-runner variance, not for one runner drifting over time. Three PRs showed it: #411 (deps only) failed on filetree on linux and crashlog on macOS; #413 (one _test.go file in internal/github) and #414 (one file in cmd/) both failed on macOS blaming internal/ai and internal/config. The same code passed on main after merge. A local benchstat A/B on #411 showed the flagged benchmark 9.77% faster, not slower. scripts/bench-interleaved.sh compiles both versions up front, then alternates between them one round at a time, so both are sampled across the same window and drift applies equally. The version that runs first alternates each round so neither absorbs any per-round warm-up cost. Total benchmark time is unchanged. The PR comment now lists which benchmarks were flagged and how to confirm locally, so a false positive is diagnosable without downloading artifacts. Closes #412 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 98ae0c9c-bdbe-418e-8488-15082edca7dc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #401
Problem
urlRewriteTransport.RoundTripdelegated to the process-globalhttp.DefaultTransport, so every mock client built bysetupMockClientshared one connection pool. That coupled all 13t.Parallel()tests in the package to each other'shttptestserver teardown.The symptom was intermittent race-detector CI failures that looked like real regressions on unrelated PRs, such as this one on #395, which touched only
cmd/clean.go,cmd/clean_test.go, and a docs page:Fix
Give each mock client its own transport, and drain it on cleanup.
http.DefaultTransport.Clone()rather than a fresh&http.Transport{}so the transport keeps the same settings it had before (timeouts, HTTP/2 attempt, proxy resolution) and only the connection pool stops being shared. This keeps the change behavior-preserving apart from the isolation itself.Cleanup ordering matters and is deliberate:
t.Cleanupruns LIFO, so registeringtransport.CloseIdleConnectionsafterserver.Closemeans the transport drains first, before the server it points at goes away.Scope
One file, 16 insertions.
setupMockClientis the single chokepoint for all 125 call sites across 6 test files, so none of them needed changes.Verification
go test ./internal/github/ -race -count=20passesgo build ./...cleango vet ./internal/github/cleangofmtcleanAcceptance criteria
urlRewriteTransportuses a per-instance transport, not the global defaultsetupMockClientcloses idle connections for its own transport on cleanupgo test ./internal/github/ -race -count=20passes consistently